package com.yejiarong.elasticsearch.common.tools;

import java.util.EnumMap;
import java.util.concurrent.TimeUnit;

/**
 * @author YeJR
 */
public class TimeUnitUtils {

    private static final EnumMap<TimeUnit, String> TIME_UNIT_ABBREVIATIONS = new EnumMap<>(TimeUnit.class);

    static {
        TIME_UNIT_ABBREVIATIONS.put(TimeUnit.MILLISECONDS, "ms");
        TIME_UNIT_ABBREVIATIONS.put(TimeUnit.SECONDS, "s");
        TIME_UNIT_ABBREVIATIONS.put(TimeUnit.MINUTES, "m");
        TIME_UNIT_ABBREVIATIONS.put(TimeUnit.HOURS, "h");
        TIME_UNIT_ABBREVIATIONS.put(TimeUnit.DAYS, "d");
    }

    public static String getAbbreviation(TimeUnit unit) {
        return TIME_UNIT_ABBREVIATIONS.get(unit);
    }
}
